﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;
namespace project
{
    public partial class InputBookPage : UIForm
    {
        public InputBookPage()
        {
            InitializeComponent();
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void ClearTextBox()
        {
            uiTextBox1.Clear();
            uiTextBox2.Clear();
            uiTextBox3.Clear();
            uiTextBox4.Clear();
            uiTextBox5.Clear();
            uiTextBox6.Clear();
            uiTextBox7.Clear();
        }


        private void uiButton1_Click(object sender, EventArgs e)
        {
            string ISBN = uiTextBox1.Text.Trim();
            string BookName = uiTextBox2.Text.Trim();
            string BookAuthor = uiTextBox3.Text.Trim();
            string category = uiTextBox4.Text.Trim();
            string Publisher = uiTextBox5.Text.Trim();
            string Store = uiTextBox6.Text.Trim();
            string location = uiTextBox7.Text.Trim();


            if (string.IsNullOrEmpty(ISBN) ||
                string.IsNullOrEmpty(BookName) ||
                string.IsNullOrEmpty(BookAuthor) ||
                string.IsNullOrEmpty(Publisher) ||
                string.IsNullOrEmpty(category) ||
                string.IsNullOrEmpty(Store) ||
                string.IsNullOrEmpty(location))
            {
                MessageBox.Show("存在空数据，请检查后再添加", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }



            string sqlStr = $"insert into books (number,name,author,category,publish,repertory,total_mount,location) values ('{ISBN}','{BookName}','{BookAuthor}','{category}','{Publisher}',{int.Parse(Store)},{int.Parse(Store)},'{location}');";

            int reslut = SqlHelper.ExecuteNonQuery(sqlStr);
            if (reslut == 1)
            {

                MessageBox.Show("添加图书信息成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                ClearTextBox();
            }
            else
            {
                MessageBox.Show("添加图书信息失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        
    }
}
